import util  from "@/utils/util"

const concatPlayList = function(list,playList=[]){ //过滤没有版权与vip的歌曲
    return util.concatPlayList(list.filter(item=>{return !item.license && !item.vip}),playList)
}
const findIndex = (list, playList) => {
    return playList.findIndex(d => { return d.id === list.id })//返回去重后的数组与当前歌曲相同id的索引 
}
export default{
    selectPlay({commit,state},{list}){  //选择歌曲并立即播放
        const playlist = concatPlayList(list,state.playList);//合并vuex里的歌曲与新传来的数据并去重
        commit('setPlayList',playlist);
        commit('setIsPlayed',true);
        commit('setPlayIndex',findIndex(list[0],playlist));//拿到新传递过来的歌曲的id并在合并之后重新找到与此id一致的索引
    }
}